package cn.regexp.business.web.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.regexp.common.base.page.TablePageInfo;
import cn.regexp.domain.ShopOrderGoods;
import cn.regexp.service.IOrderGoodsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.List;

/**
 * 订单菜品控制器
 */
@Slf4j
@Controller
@RequestMapping("business/orderGoods")
public class OrderGoodsController {

    @Autowired
    private IOrderGoodsService orderGoodsService;

    //删除
    @RequiresPermissions("business:orderGoods:queryByOrderId")
    @RequestMapping("/queryByOrderId")
    @ResponseBody
    public TablePageInfo<ShopOrderGoods> queryByOrderId(Long orderId) {
        if (ObjectUtil.isEmpty(orderId)) {
            return new TablePageInfo<>(Collections.emptyList());
        }
        QueryWrapper<ShopOrderGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orderId);
        List<ShopOrderGoods> shopOrderList = orderGoodsService.list(wrapper);
        return new TablePageInfo<>(shopOrderList, orderGoodsService.count(wrapper));
    }
}
